package owg.util.editor2d;

import java.util.LinkedHashSet;

import owg.util.editor2d.operations.Operation;
/**Stores the complete selection info for a single undo/redo step.
 * <br/><br/>
 * Note that this class extends {@link Operation} because that way the selection can be saved to the map file.
 * <font color = RED>Edits that modify the selection should <b>not</b> use this class!</font> 
 * StateInfo objects are stored separately for each undo record: Edits that only modify the selection should use 
 * {@link Operation#NO_OPERATION} for both forward and backward operation arguments.*/
public class StateInfo extends Operation
{
	LinkedHashSet<Integer> selectedIndices;
	/**Constructs a new {@link StateInfo}, copying the indicated set.*/
	public StateInfo(LinkedHashSet<Integer> selectedIndices)
	{
		this.selectedIndices = new LinkedHashSet<Integer>(selectedIndices);
	}
	/**Sets the currently selected indices in the editor to the index set recorded in this {@link StateInfo}*/
	public void apply(Editor2D w)
	{
		w.setSelectedIndices(selectedIndices, false);
	}
	@Override
	public String toString()
	{
		return selectedIndices.toString();
	}
	/**Compares this to another StateInfo and returns whether the selected indices are the same.*/
	@Override
	public boolean equals(final Object o)
	{
		if(o instanceof StateInfo)
			return compareSet((((StateInfo) o).selectedIndices));
		return false;
	}
	/**Compares this to another StateInfo and returns whether the selected indices are the same.*/
	public boolean compareSet(LinkedHashSet<Integer> indices)
	{
		return (indices != null && indices.equals(selectedIndices));
	}
}
